package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Category;
import com.example.entity.Tag;
import com.example.service.TagService;
import com.example.mapper.TagMapper;
import com.example.utils.ResponseResult;
import com.example.utils.SecurityUtils;
import com.example.vo.PageVo;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author sprite-pc
* @description 针对表【sg_tag(标签)】的数据库操作Service实现
* @createDate 2023-12-31 17:56:55
*/
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService{

    @Override
    public List<Tag> listAllTag() {
        return list();
    }

    @Override
    public ResponseResult getList(int pageNum, int pageSize, String name) {
        Page<Tag> tagPage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<Tag> queryWrapper = new LambdaQueryWrapper<>();
        if (name!=null){
            queryWrapper.like(Tag::getName,name);
        }
        queryWrapper.eq(Tag::getCreateBy, SecurityUtils.getUserId());
        page(tagPage,queryWrapper);
        PageVo pageVo = new PageVo(tagPage.getRecords(),tagPage.getTotal());

        return ResponseResult.okResult(pageVo);
    }

    @Override
    public ResponseResult saveTag(Tag tag) {
        tag.setCreateBy(SecurityUtils.getUserId());
        tag.setCreateTime(new Date());
        save(tag);
        return ResponseResult.okResult();
    }
}




